set more off
clear all

global BHHDIR Dropbox\INE\data\bhh
global ENIADIR Dropbox\INE\data\enia
global IPDIR Dropbox\INE\data\matchip
global INNODIR Dropbox\INE\data\Innovacion
global DIR Dropbox\INE\EDCC_files

**********************************************************************************
*** Master file for data construction. Fink, Hall, and Helmers 2020, "Intellectual
*** Property Use and Firm Performance: The Case of Chile," Economic Development
*** and Cultural Change
*** BHH Jan 2020
**********************************************************************************

*** Create the ENIA file from the individual year spreadsheets; aggregate to firm
*** level from establishment level.
do $DIR\cr_enia

*** Correct some jumps in capital stock using constructed capital stock; this
*** involved some manual checking of data.
do $DIR\cr_capital_stock

*** Merge the trademark and other IP data into a single file, and then merge 
*** that file with the ENIA data by firm id and year.
do $DIR\cr_enia_ip

*** Merge all 3 files (ENIA, IP, and Innovation surveys) with all years available;
*** variables renamed to removed the id_ prefix.
do $DIR\mg_all

*** Extract data from the merged file and rename/recode some variables.
do $DIR\extract

*** Create firm-level market share variables for 2- and 4-digit industries.
do $DIR\cr_mktshare

*** Create sample for analysis: 1) reduce industries; 2) define some variables for
*** the regression; 3) drop firms with missing employment or capital stock, large
*** year to year growth rates, or only one year of data; 4) create HHI and share
*** of foreign sales for Table B-5.
do $DIR\cr_sample

*** Merge in the tfp estimates from cr_tfp, some additional cleaning, correct
*** investment and elec variables.
do $DIR\cr_sample_clean

